package com.wgy.day20.发红包练习;

import java.util.ArrayList;
import java.util.Random;
//红包派分接口的实现类,随机分配
public class RandomMode implements OpenMode {
    @Override
    public ArrayList<Integer> divide(int totalMoney, int totalCount) {

        ArrayList<Integer> list =new ArrayList<Integer>();
        Random r=new Random();
        int leftMoney=totalMoney;
        int leftCount=totalCount;
        for (int i = 0; i < totalCount-1; i++) {
            int money=r.nextInt(leftMoney/leftCount*2)+1;
            list.add(money);
            leftMoney=leftMoney-money;
            leftCount--;

        }
        list.add(leftMoney);
        return list;
    }
}
